package com.yx.frame.jdbc.pool;

import java.sql.Connection;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public final class C3p0Pool implements Pool {
	String name = null;
	int maxQueryRowCountList = 5000;	
	private ComboPooledDataSource cpds;

	public C3p0Pool(String aname, String JDBCDriver, String JDBCUrl,
			String JDBCUser, String JDBCPassword, int apoolSize, int amaxConn,
			int agetConnTimeout,int maxQueryRowCountList,int maxIdleTime,int acquireIncrement) throws Exception {
		this.name = aname;
		this.maxQueryRowCountList = maxQueryRowCountList;		
		cpds = new ComboPooledDataSource(true);
		cpds.setDataSourceName(aname);
		cpds.setJdbcUrl(JDBCUrl);
		cpds.setDriverClass(JDBCDriver);
		cpds.setUser(JDBCUser);
		cpds.setPassword(JDBCPassword);
		cpds.setMaxPoolSize(amaxConn);
		cpds.setMinPoolSize(apoolSize);
		cpds.setAcquireIncrement(acquireIncrement);
		cpds.setInitialPoolSize(apoolSize);
		cpds.setMaxIdleTime(maxIdleTime);
	}

	public String getName() {
		return name;
	}

	public PConnection getConnection() throws Exception {
		Connection conn = cpds.getConnection();
		PConnection pConnection = new PConnection(conn);
		return pConnection;
	}
	public int getMaxQueryRowCount() {
		return maxQueryRowCountList;
	}
	public boolean isFramePool(){
		return true;
	}
	
	//定义方法,返回ComboPooledDataSource实现类的对象
	public ComboPooledDataSource getDataSource(){
		return cpds;
	}		
	
	
}
